package com.imax.emap.projection
{
	import com.imax.emap.core.LatLon;
	
	import flash.geom.Point;

	public class LingtuProjection implements IProjection
	{
		private var imgSize:int = 200;
		private var imgNtuSize:int = 256;
		private var bitmapOrigo:Array;
		private var numTiles:Array;
		
		public function LingtuProjection(maxZoom:int=20,tileWidth:int=200)
		{
			
  			bitmapOrigo = new Array();
  			numTiles = new Array();
  			
			for(var d:int=0;d<maxZoom;d++)
			{
				var e:Number=tileWidth/2;
    			//pixelsPerLonDegree.push(tileWidth/360);
    			//pixelsPerLonRadian.push(tileWidth/(2*Math.PI));
    			bitmapOrigo.push(new Point(e,e));
    			numTiles.push(tileWidth);
    			tileWidth*=2;
   			}
		}

		public function fromPixelToLatLon(p:Point, zoom:int):LatLon
		{
			var zoomUnits:Number=Math.pow(2,17-zoom)*this.imgNtuSize/this.imgSize;
			//var latlng=K_51dituProjection.NtuToLatlng([point.x*zoomUnits,-point.y*zoomUnits]);
			return new LatLon(-p.y*zoomUnits,p.x*zoomUnits);
		}
		
		/**
		 * 
		 * @param latLon 这里是NTU，不是经纬度
		 * @param zoom 缩放等级
		 * @return 某点的像素
		 * 
		 */		
		public function fromLatLonToPixel(latLon:LatLon, zoom:int):Point
		{
			var zoomUnits:Number=Math.pow(2,17-zoom)*this.imgNtuSize/this.imgSize;
			//var ntu=K_51dituProjection.LatlngToNtu([point.lng()*100000,point.lat()*100000]);
			return new Point(latLon.lon/zoomUnits,-latLon.lat/zoomUnits);
		}
		
		public function getTileWidth(zoom:int):Number
		{
			return Math.pow(2,zoom+8);
		}
		
		public function getTileHeight(zoom:int):Number
		{
			return Math.pow(2,zoom+8);
		}
		
	}
}